package core;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import model.AdminUser;
import observers.AlteracoesSistema;
import observers.ProjetoObserver;
import org.hibernate.Session;
import org.hibernate.cfg.Configuration;
import validation.Validator;

//Facade e Singleton
public class App {

    private static App instance = new App();
    private static List<String> errors = new ArrayList<String>();
    private static List<String> messages = new ArrayList<String>();
    private static HashMap values = new HashMap();
    private static List<AdminUser> admins = new ArrayList<AdminUser>();
    private static AlteracoesSistema alteracoesProjeto = new AlteracoesSistema();
    private static AlteracoesSistema alteracoesUsuario = new AlteracoesSistema();
    private static Boolean initialized = false;

    private App() {
    }

    public static void initialize() {
        if (!initialized) {
            /*
             * Inicialia uma lista de admins
             */
            admins.add(new AdminUser("Daniel Schmitz", "danieljfa@gmail.com"));
            admins.add(new AdminUser("Anderson Vieira", "andervs@gmail.com"));

            //Primeiro observer
            alteracoesProjeto.addObserver(new ProjetoObserver());
            
            
            
            
            
            initialized = true;
        }
    }

    public static AlteracoesSistema getAlteracoesProjeto() {
        return alteracoesProjeto;
    }

    public static App getInstance() {
        return instance;
    }

    public String IntToStr(int i) {
        return Integer.toString(i);
    }

    public Integer StrToInt(String s) {
        return Integer.getInteger(s);
    }

    public Session getSession() {
        return new Configuration().configure().buildSessionFactory().openSession();
    }

    public static void addError(String error) {
        errors.add(error);
    }

    public static void clearError() {
        errors.clear();
    }

    public static List<String> getErrors() {
        return errors;
    }

    public static void addMessage(String msg) {
        messages.add(msg);
    }

    public static void clearMessage() {
        messages.clear();
    }

    public static List<String> getMessages() {
        return messages;
    }

    public void setAttribute(String key, Object value) {
        values.put(key, value);
    }

    public Object getAttribute(String key) {
        return values.get(key);
    }
}
